<?php

namespace App\Admin\Controllers;

use App\Miya\Models\ChatRecord;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;

class ChatRecordController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '在线咨询记录';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ChatRecord());
        $grid->model()->orderBy('id', 'DESC');

        $grid->column('id', '序号');
        $grid->column('phone', '手机号码')->label();
        $grid->column('ip', 'ip')->label();
        $grid->column('content', '信息');
        $grid->column('created_at', '创建时间')->display(function () {
            return $this->created_at->format('Y-m-d H:i:s');
        });
        $grid->column('status', '状态')->radio(ChatRecord::$stats);

        $grid->filter(function (Grid\Filter $filter) {
            $filter->scope('phone', '提交手机号码')->where(function ($query) {
                $query->where('phone', '<>', '');
            });
        });

        $grid->disableActions();
        $grid->disableCreateButton();

        return $grid;
    }


    protected function form()
    {
        $form = new Form(new ChatRecord());

        $form->select('status', '状态')->options(ChatRecord::$stats);

        return $form;
    }
}
